import request from '@/utils/request'
import qs from 'qs'

// 获取单位列表
export function listUnits() {
    return request({
        url: '/md/unit/list',
        method: 'get'
    })
}
// 分页查询
export function pageRefund(data) {
    return request({
        url: '/refund/page',
        method: 'post',
        data
    })
}

// post提交，如果需要提交数据，数据必须赋值给data属性
export function addUnit(data) {
    return request({
        url: '/md/unit/add',
        method: 'post',
        data   // data: data
    })
}

// 查询主单位
export function listPrimary() {
    return request({
        url: '/md/unit/list/primary',
        method: 'get'
    })
}

// 查询所有单位
export function listAllUnit() {
    return request({
        url: '/md/unit/list/all',
        method: 'get'
    })
}

// get提交，参数通过params传，或者将参数放到路径中
export function deleteUnit(eid) {
    return request({
        url: '/md/unit/delete',
        method: 'get',
        params: { id: eid }
    })
}

export function deleteUnitBatch(data) {
    return request({
        url: '/md/unit/delete/batch',
        method: 'post',
        data
    })
}

export function updateUnit(data) {
    return request({
        url: '/md/unit/update',
        method: 'post',
        data   // data: data
    })
}

export function unitInfo(params) {
    return request({
        url: '/md/unit/info',
        method: 'get',
        params
    })
}

export function exportUnit(){
    return request({
        url: '/md/unit/export',
        method: 'get',
        responseType: 'blob',
    })
}

export function download(data, name) {
    if (!data) {
        return;
    }
    let url = window.URL.createObjectURL(new Blob([data], { type: "application/vnd.ms-excel" }));
    let link = document.createElement('a');
    link.style.display = 'none';
    link.href = url;
    link.setAttribute('download', name);
    document.body.appendChild(link);
    link.click();
}